package com.example.administrator.damaiwang.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.damaiwang.Activity.App;
import com.example.administrator.damaiwang.R;
import com.example.administrator.damaiwang.Utils.NetUtils;
import com.example.administrator.damaiwang.bean.LBean;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by Administrator on 2016/12/12.
 */
public class MyListAdapter extends BaseAdapter {
    private ViewHolder holder;
    private Context context;
    private List<LBean> list;
    private String BASR_URL1 = "http://pimg.damai.cn/perform/project/";
    public MyListAdapter (Context context, List<LBean> list){
        this.list=list;
        this.context=context;
    }
    @Override
    public int getCount() {
        return list!=null?list.size():null;
    }

    @Override
    public Object getItem(int position) {
        return list!=null?list.get(position):null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView ==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.list_items,parent,false);
            holder=new ViewHolder();
            holder.iv= (ImageView) convertView.findViewById(R.id.iv);
            holder.tvJiaGe= (TextView) convertView.findViewById(R.id.tv_jiage);
            holder.tvJuChang= (TextView) convertView.findViewById(R.id.tv_yingyuan);
            holder.tvKaiQi= (TextView) convertView.findViewById(R.id.tv_kaiqi);
            holder.tvShiJian= (TextView) convertView.findViewById(R.id.tv_shijian);
            holder.tvShouPiao= (TextView) convertView.findViewById(R.id.tv_shoupiao);
            holder.tvTitle= (TextView) convertView.findViewById(R.id.tv_title);
            holder.tvYuShou= (TextView) convertView.findViewById(R.id.tv_yushou);
            holder.tvZuo= (TextView) convertView.findViewById(R.id.tv_zuo);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        holder.tvTitle.setText(list.get(position).getN());
        holder.tvJiaGe.setText(list.get(position).getPriceName());
        holder.tvJuChang.setText(list.get(position).getVenName());
        holder.tvShiJian.setText(list.get(position).getT());
        String s=list.get(position).getSummary();
        if (!TextUtils.isEmpty(s)) {
            holder.tvKaiQi.setText(list.get(position).getSummary());
        }else {
            holder.tvKaiQi.setVisibility(View.GONE);
        }
        String i = String.valueOf(list.get(position).getI());
        String imageUrl = BASR_URL1 + i.substring(0,4) +"/"+i+"_n.jpg";
        if (NetUtils.isConnect()){
        Picasso.with(context).load(imageUrl).into(holder.iv);
        }else {
            Toast.makeText(App.context,"请检查网络设置",Toast.LENGTH_SHORT).show();
        }
        return convertView;
    }
    public class ViewHolder{
        TextView tvTitle,tvZuo,tvShouPiao,tvYuShou,tvShiJian,tvJuChang,tvJiaGe,tvKaiQi;
        ImageView iv;

    }

}
